<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS的数据类型</title>
</head>
<body>
<script>
    //JS数据类型 = 原始类型 + 引用类型
    //原始类型:number string boolean null undefined
    var a = 1;
    var b = 9.9;//整数小数都是number
    console.log(a, typeof a, b, typeof b);
    var c = 'hello';
    var d = "world";//单引双引都是string
    console.log(c, typeof c, d, typeof d);
    var e = true;
    var f = false;//true与false是boolean
    console.log(e, typeof e, f, typeof f);
    var g;
    console.log(g, typeof g);//声明了变量但未赋值是 undefiend 未定义型

    //引用类型 Array Object Function ...
    let obj = {};
    console.log(obj, typeof obj);//{} 'object'
    obj.name = '张三';
    obj.age = 18;
    console.log(obj, typeof obj);//{name: '张三', age: 18} 'object'
    console.log(obj.name, obj.age);

    //自定义对象的第2种写法
    let obj2 = {
        name: '李四',
        age: 20
    };
    obj2.gender = '男';
    console.log(obj2, typeof obj2);//{name: '李四', age: 20} 'object'
    console.log(obj2.name, obj2.age, obj2.gender);

    //数组
    let arr = ['张三',1,6.6,true];
    console.log(arr);
    console.log(arr[0],arr[1],arr[2],arr[3]);
    console.log(arr[100]);//undefined 访问数组中不存在的元素也会得到 undefined

    //Number() 将参数转为数字 如果无法成功得到数字类型的结果,就会得到NaN(Not a Number)
    console.log(Number(true),typeof Number(true));//1 'number'
    console.log(Number(false));//0
    console.log(Number('3'));//3
    console.log(Number(3));//3
    console.log(Number(6.6));//6.6
    console.log(Number('哈哈哈'));//NaN

    //Boolean() 将参数转为布尔值
    //0,NaN,null,undefined,false,'' 这5个特殊值转为布尔是false
    console.log(Boolean(0),typeof Boolean(0));//false 'boolean'
    console.log(Boolean(null));
    console.log(Boolean(undefined));
    console.log(Boolean(NaN));
    console.log(Boolean(''));
    console.log(Boolean('早上好'));//true
    console.log(Boolean(' '));//true
    console.log(Boolean(1));//true






</script>
</body>
</html>